<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\adminapi\logic;


use app\common\model\TbHxwt;
use app\common\logic\BaseLogic;
use think\facade\Db;


/**
 * TbHxwt逻辑
 * Class TbHxwtLogic
 * @package app\adminapi\logic
 */
class TbHxwtLogic extends BaseLogic
{


    /**
     * @notes 添加
     * @param array $params
     * @return bool
     * @author likeadmin
     * @date 2025/03/22 11:34
     */
    public static function add(array $params): bool
    {
        Db::startTrans();
        try {
            TbHxwt::create([
                '工单号' => $params['工单号'],
                '状态' => $params['状态'],
                '工单类型' => $params['工单类型'],
                '分配机构' => $params['分配机构'],
                '分配人员' => $params['分配人员'],
                '参与人员' => $params['参与人员'],
                '业务标识' => $params['业务标识'],
                '产品IMEI旧' => $params['产品IMEI旧'],
                '序列号旧' => $params['序列号旧'],
                '产品品牌' => $params['产品品牌'],
                '产品型号' => $params['产品型号'],
                '产品颜色' => $params['产品颜色'],
                '产品容量' => $params['产品容量'],
                '保单号' => $params['保单号'],
                '密码' => $params['密码'],
                '保修状态' => $params['保修状态'],
                '报修服务类型' => $params['报修服务类型'],
                '用户名称' => $params['用户名称'],
                '手机号码' => $params['手机号码'],
                '产品IMEI新' => $params['产品IMEI新'],
                '序列号新' => $params['序列号新'],
                '产品品牌新' => $params['产品品牌新'],
                '产品型号新' => $params['产品型号新'],
                '产品颜色新' => $params['产品颜色新'],
                '产品容量新' => $params['产品容量新'],
                '旧机回收价格' => $params['旧机回收价格'],
                '更换时间' => $params['更换时间'],
                '免赔价差' => $params['免赔价差'],
                '理赔额度' => $params['理赔额度'],
                '工单备注' => $params['工单备注'],
                '服务结果' => $params['服务结果'],
                '实收金额' => $params['实收金额'],
                '收款结果' => $params['收款结果'],
                '收款备注' => $params['收款备注'],
                '发货类型' => $params['发货类型'],
                '快递公司' => $params['快递公司'],
                '快递单号' => $params['快递单号'],
                '发货备注' => $params['发货备注'],
                '服务单状态' => $params['服务单状态']
            ]);

            Db::commit();
            return true;
        } catch (\Exception $e) {
            Db::rollback();
            self::setError($e->getMessage());
            return false;
        }
    }


    /**
     * @notes 编辑
     * @param array $params
     * @return bool
     * @author likeadmin
     * @date 2025/03/22 11:34
     */
    public static function edit(array $params): bool
    {
        Db::startTrans();
        try {
            TbHxwt::where('id', $params['id'])->update([
                '工单号' => $params['工单号'],
                '状态' => $params['状态'],
                '工单类型' => $params['工单类型'],
                '分配机构' => $params['分配机构'],
                '分配人员' => $params['分配人员'],
                '参与人员' => $params['参与人员'],
                '业务标识' => $params['业务标识'],
                '产品IMEI旧' => $params['产品IMEI旧'],
                '序列号旧' => $params['序列号旧'],
                '产品品牌' => $params['产品品牌'],
                '产品型号' => $params['产品型号'],
                '产品颜色' => $params['产品颜色'],
                '产品容量' => $params['产品容量'],
                '保单号' => $params['保单号'],
                '密码' => $params['密码'],
                '保修状态' => $params['保修状态'],
                '报修服务类型' => $params['报修服务类型'],
                '用户名称' => $params['用户名称'],
                '手机号码' => $params['手机号码'],
                '产品IMEI新' => $params['产品IMEI新'],
                '序列号新' => $params['序列号新'],
                '产品品牌新' => $params['产品品牌新'],
                '产品型号新' => $params['产品型号新'],
                '产品颜色新' => $params['产品颜色新'],
                '产品容量新' => $params['产品容量新'],
                '旧机回收价格' => $params['旧机回收价格'],
                '更换时间' => $params['更换时间'],
                '免赔价差' => $params['免赔价差'],
                '理赔额度' => $params['理赔额度'],
                '工单备注' => $params['工单备注'],
                '服务结果' => $params['服务结果'],
                '实收金额' => $params['实收金额'],
                '收款结果' => $params['收款结果'],
                '收款备注' => $params['收款备注'],
                '发货类型' => $params['发货类型'],
                '快递公司' => $params['快递公司'],
                '快递单号' => $params['快递单号'],
                '发货备注' => $params['发货备注'],
                '服务单状态' => $params['服务单状态']
            ]);

            Db::commit();
            return true;
        } catch (\Exception $e) {
            Db::rollback();
            self::setError($e->getMessage());
            return false;
        }
    }


    /**
     * @notes 删除
     * @param array $params
     * @return bool
     * @author likeadmin
     * @date 2025/03/22 11:34
     */
    public static function delete(array $params): bool
    {
        return TbHxwt::destroy($params['id']);
    }


    /**
     * @notes 获取详情
     * @param $params
     * @return array
     * @author likeadmin
     * @date 2025/03/22 11:34
     */
    public static function detail($params): array
    {
        return TbHxwt::findOrEmpty($params['id'])->toArray();
    }
}